package com.scut.scutzone.util;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.apache.tomcat.util.buf.StringUtils;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: hg chen
 * @Date: 2021/5/9
 * @Time: 0:03
 * @Description:用来处理img_name在java类与数据库之间的映射关系
 */
public class imgNameHandler implements TypeHandler<String[]> {
    @Override
    public void setParameter(PreparedStatement preparedStatement, int i, String[] strings, JdbcType jdbcType) throws SQLException {


        String real_imgs_name = SZUtil.getRealImgsName(strings);
        try {
            preparedStatement.setString(i, real_imgs_name);
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    @Override
    public String[] getResult(ResultSet resultSet, String s) throws SQLException {

        String[] img_name = SZUtil.parseRealImgsName(resultSet.getString(s));
        return img_name;


    }

    @Override
    public String[] getResult(ResultSet resultSet, int i) throws SQLException {

        String[] img_name = SZUtil.parseRealImgsName(resultSet.getString(i));
        return img_name;

    }

    @Override
    public String[] getResult(CallableStatement callableStatement, int i) throws SQLException {
        String real_imgs_name = callableStatement.getString(i);
        String[] img_name = SZUtil.parseRealImgsName(real_imgs_name);
        return img_name;
    }
}
